<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width='device-width', initial-scale=1.0">
  <title>8、reduce map 迭代器，有什么不同 ①.实现函数：同时使⽤ reduce map 迭代器，让数组内所有的 偶数求和 ②.实现函数：只使⽤ reduce 求奇数之和 </title>
</head>

<body>
  <script>
    let arr = [1, 2, 3, 4, 6]
    //map是会生成新的数组
    var fn = arr.map(() => {
      //a:上一次回调的返回值
      //b:是正在执行的
      //reduce是接收一个值返回一个
      var fm = arr.reduce((a, b) => {
        if (b % 2 == 0) {
          return a + b
        }
        return a
      }, 0)
      return fm
    })
    //数组每次都调用
    for (i in fn) { }
    console.log(fn[i])





    //a:上一次调用回调的返回值
    //b:是正在执行的
    let array = [2, 3, 4, 5, 6, 7]
    var num = array.reduce((a, b) => {
      // console.log(b);
      if (b % 2 != 0) {
        return a + b
      }
      return a
    }, 0)
    console.log(num)
  </script>
</body>

</html>